package com.yq.spbYq.mapper;

import com.yq.spbYq.WasteRecord;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface WasteRecordMapper {
    //查询数据
    @Select("SELECT * FROM wasterecord")
    @Results({
            @Result(property = "id", column = "gr_id"),
            @Result(property = "residentId", column = "gr_resident_id"),
            @Result(property = "type", column = "gr_type"),
            @Result(property = "time", column = "gr_time"),
            @Result(property = "weight", column = "gr_weight"),
            @Result(property = "location", column = "gr_location"),
            @Result(property = "status", column = "gr_status")
    })

    public List<WasteRecord> selectWasteRecord();
    @Select("SELECT * FROM wasterecord WHERE gr_resident_id = #{residentId}")
    @Results({
            @Result(property = "id", column = "gr_id"),
            @Result(property = "residentId", column = "gr_resident_id"),
            @Result(property = "type", column = "gr_type"),
            @Result(property = "time", column = "gr_time"),
            @Result(property = "weight", column = "gr_weight"),
            @Result(property = "location", column = "gr_location"),
            @Result(property = "status", column = "gr_status")
    })
    public List<WasteRecord> selectWasteRecordByResidentId(Long residentId);

    @Insert("INSERT INTO wasterecord (gr_resident_id, gr_type, gr_time, gr_weight, gr_location, gr_status) " +
            "VALUES (#{residentId}, #{type}, #{time}, #{weight}, #{location}, #{status})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    public void insertWasteRecord(WasteRecord wasteRecord);

    @Delete("DELETE FROM wasterecord WHERE gr_resident_id = #{id}")
    public void deleteWasteRecord(Long id);
}
